import buildingApi from '@/config/server/api/building.js'
import biApi from '@/config/server/api/bi'
import userApi from '@/config/server/api/user.js'
import baseApi from '@/config/server/api/base.js'
import dt from '@dt/dt'
//查询全部案场
function buildinghousesList(params) {
  return buildingApi.caseList.buildinghousesList.fetch(params).then((res) => {
    res.list &&
      res.list.map((item) => {
        dt.dictInfo().buildStatus.map((itemF) => {
          if (itemF.key == item.status) {
            item.status = itemF.value
          }
        })
        dt.dictInfo().cooperationModeAttrSort.map((itemC) => {
          if (itemC.key == item.cooperationMode) {
            item.cooperationMode = itemC.value
            item.cooperationModeKey = itemC.key
          }
        })

        // let projectArr = [],
        //   womenCollegeArr = []
        // item.projectList.length > 0 &&
        //   item.projectList.map((itemT) => {
        //     projectArr.push(itemT.userName + '(' + itemT.workNo + ')')
        //   })
        // item.projectStr = projectArr.join(',')

        // item.womenCollegeList.length > 0 &&
        //   item.womenCollegeList.map((itemT) => {
        //     womenCollegeArr.push(itemT.userName + '(' + itemT.workNo + ')')
        //   })
        // item.womenCollegeStr = womenCollegeArr.join(',')
      })
    return res
  })
}

// 关注/取消关注案场
function housesConcern(params) {
  return buildingApi.caseList.housesConcern.fetch(params)
}
//关注的案场列表
function housesConcernList(params) {
  return buildingApi.caseList.housesConcernList.fetch(params).then((res) => {
    res.list &&
      res.list.map((item) => {
        dt.dictInfo().buildStatus.map((itemF) => {
          if (itemF.key == item.status) {
            item.status = itemF.value
          }
        })
        dt.dictInfo().cooperationModeAttrSort.map((itemC) => {
          if (itemC.key == item.cooperationMode) {
            item.cooperationMode = itemC.value
          }
        })

        // let projectArr = [],
        //   womenCollegeArr = []
        // item.projectList.length > 0 &&
        //   item.projectList.map((itemT) => {
        //     projectArr.push(itemT.userName + '(' + itemT.workNo + ')')
        //   })
        // item.projectStr = projectArr.join(',')

        // item.womenCollegeList.length > 0 &&
        //   item.womenCollegeList.map((itemT) => {
        //     womenCollegeArr.push(itemT.userName + '(' + itemT.workNo + ')')
        //   })
        // item.womenCollegeStr = womenCollegeArr.join(',')
      })
    return res
  })
}
//获取案场名称列表 列表页查询条件
function getHousesNames(params, receiver) {
  return buildingApi.caseList.getHousesNames.fetch(params).then((res) => {
    if (receiver) {
      return res
    } else {
      let list = []
      list =
        res.list &&
        res.list.map((item) => {
          return {
            value: item.housesName,
            label: item.housesName
          }
        })
      return list
    }
  })
}
//获取案场人员列表 列表页查询条件
function getBuildingUserList(params) {
  return userApi.getBuildingUserList.fetch(params).then((res) => {
    console.log(res)
    let list = []
    list =
      res &&
      res.map((item) => {
        return {
          value: item.userName,
          label: item.userName,
          key: item.userName
        }
      })
    return list
  })
}
//根据权限获取组织架构
function Organization() {
  return biApi.orderReport.selectUserOrg.fetch()
}
//根据城市联级
function getAreacodePropertyList(params) {
  return baseApi.generalConfiguration.cityList().fetch(params)
}

function externalHousesList(params) {
  return buildingApi.caseList.externalHousesList.fetch(params)
}

function getNoOfficeNum(params) {
  return userApi.orgManagement.getNoOfficeNum.fetch(params)
}

function getBuildingLog(params) {
  return userApi.case.getBuildingLog.fetch(params)
}

function adjustHousesList(params) {
  return buildingApi.caseList.adjustHousesList.fetch(params)
}

function getOrganizationList1(params) {
  return userApi.organ.getWebOrg.fetch(params)
}

function updBuildingOrgBath(params) {
  return userApi.case.updBuildingOrgBath.fetch(params)
}

export default {
  buildinghousesList,
  housesConcern,
  housesConcernList,
  getHousesNames,
  getBuildingUserList,
  Organization,
  getAreacodePropertyList,
  externalHousesList,
  getNoOfficeNum,
  getBuildingLog,
  adjustHousesList,
  getOrganizationList1,
  updBuildingOrgBath
}
